<?php
/**
 * Created by PhpStorm.
 * User: ZhangWei
 * Date: 2018/3/20
 * Time: 9:46
 */

namespace App\Logic;


use EasyWeChat\Factory;
use zgldh\QiniuStorage\QiniuStorage;

class ShareLogic
{

    public static function getXcxQr($type, $item, $user)
    {
        $app = Factory::miniProgram(ConfigLogic::getWxConfig());

        if ($type == 'doc') {
            $page = 'pages/index/main';
            $scene = $item->mode . "#" . hashid_encode($item->id);
            $response = $app->app_code->getUnlimit($scene, $optional = [
                'page' => $page,
            ]);

            //$response = $app->app_code->get($page . '?scene=' . $scene);

            $disk = QiniuStorage::disk('qiniu');
            $file_name = md5($page . $scene) . '.png';
            $path = 'qr_code/' . $file_name;
            if (!$disk->exists($path)) {
                $disk->put($path, $response);
            }
            return $path;
        }
    }

}